package com.mytinyRPC.serializer;

import com.mytinyRPC.serializer.Impl.JsonSerializer;
import com.mytinyRPC.serializer.Impl.KryoSerializer;
import com.mytinyRPC.serializer.Impl.ProtobufSerializer;
/***
 * @Author HP
 * @Description //TODO 序列化公共接口
 **/
public interface CommonSerializer {
    Integer JSON_SERIALIZER = 1;
    Integer KRYO_SERIALIZER = 2;
    Integer PROTOBUF_SERIALIZER = 3;

    static CommonSerializer getByCode(int code) {
        switch (code) {
            case 1:
                return new JsonSerializer();
            case 2:
                return new KryoSerializer();
            case 3:
                return new ProtobufSerializer();
            default:
                return null;
        }
    }

    byte[] serialize(Object obj);

    Object deserialize(byte[] bytes, Class<?> clazz);

    int getCode();
}
